* Bootstrap procedure over entire causal link:
capture program drop layersbootstrap
program define layersbootstrap, rclass

	preserve
	bsample , cluster(firmcode) idcluster(newfirmcode)
	
	sort newfirmcode t
	xtset newfirmcode t

	* First stage identical for all cases:
	xtreg logva I_WID I_transport_f2 yeardummy* sectordummy* if sample == 1, fe
	cap drop logsalespred
	predict logsalespred, xbu
	
	* GMM, ma(1) errors, one-step
	xtabond2 layers L.layers logsalespred ///
	sectordummy1-sectordummy8 yeardummy4-yeardummy12 if sample == 1, ///
	gmmstyle(L.layers, lag(3 .)) gmmstyle(logsalespred, lag(4 .)) robust
	return scalar layers_ivva = _b[L.layers]
	return scalar sales_ivva = _b[logsalespred]
	cap drop layers_ivva_all
	predict layers_ivva_all
	
	areg log2inequality1 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality1_ivva = _b[layers_ivva_all]
	areg log2inequality2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality2_ivva = _b[layers_ivva_all]
	areg log2inequality3 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality3_ivva = _b[layers_ivva_all]
	areg log2inequality4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality4_ivva = _b[layers_ivva_all]
	areg log2inequality5 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar log2inequality5_ivva = _b[layers_ivva_all]
	areg wagegap1_topbottom_log layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_log_ivva = _b[layers_ivva_all]
	
	areg res2inequality1_model2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_ivva = _b[layers_ivva_all]
	areg res2inequality2_model2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_ivva = _b[layers_ivva_all]
	areg res2inequality3_model2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality3_ivva = _b[layers_ivva_all]
	areg res2inequality4_model2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_ivva = _b[layers_ivva_all]
	areg res2inequality5_model2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_ivva = _b[layers_ivva_all]
	areg wagegap1_topbottom_res2 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res2_ivva = _b[layers_ivva_all]
	
	areg res2inequality1_model4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality1_ivva_v2 = _b[layers_ivva_all]
	areg res2inequality2_model4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality2_ivva_v2 = _b[layers_ivva_all]
	areg res2inequality3_model4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality3_ivva_v2 = _b[layers_ivva_all]
	areg res2inequality4_model4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality4_ivva_v2 = _b[layers_ivva_all]
	areg res2inequality5_model4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar res2inequality5_ivva_v2 = _b[layers_ivva_all]
	areg wagegap1_topbottom_res4 layers_ivva_all yeardummy* sectordummy* if sample0 == 1, absorb(newfirmcode)
	return scalar wagegap1_topbottom_res4_ivva_v2 = _b[layers_ivva_all]
	
	restore
end
